//
//  YQAssetVC.m
//  NewRetail
//
//  Created by yuqin on 2019/6/23.
//  Copyright © 2019年 yuqin. All rights reserved.
//

#import "YQAssetVC.h"
#import "YQAssetsHeadView.h"
#import "YQThreeBtnView.h"
#import "YQAssetsCell.h"
#import "YQNewWalletAddressVC.h"
#import "YQNoDataView.h"
#import "YQSanningCodeVC.h"
#import "YQCollectionVC.h"
#import "YQTransferVC.h"
#import "DYLeftSlipManager.h"
#import "YQLeftTableView.h"
#import "YQManagerWalletVC.h"

@interface YQAssetVC ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>

@property (nonatomic, strong) YQAssetsHeadView *assetsHeadView;
@property (nonatomic, strong) YQThreeBtnView *threeBtn;

@property (nonatomic, strong) UITableView *assetTableView;
@property (nonatomic, strong) NSMutableArray *dataArr;
@property (nonatomic, strong) YQNoDataView *nodataView;

@end

@implementation YQAssetVC
//真的很强？
//邀请者
//嘻嘻
- (void)viewDidLoad {
    [super viewDidLoad];
    self.txtTitle.text = @"资产";
    [self.btnLeft setImage:YQ_IMAGE(@"spreads") forState:UIControlStateNormal];
    [self.btnLeft addTarget:self action:@selector(showLeftView) forControlEvents:UIControlEventTouchUpInside];
    self.view.backgroundColor = UIColorFromRGB(0xf5f6f7);
    [self setupAssetView];
//    YQLeftTableView *leftTableView = [[YQLeftTableView alloc] init];
//    @weakify(self);
//    leftTableView.PushBlock = ^{
//        @strongify(self);
//        YQ_PUSH([YQManagerWalletVC new]);
//    };
}

- (void)showLeftView {
    [[DYLeftSlipManager sharedManager] showLeftView];
}

#pragma mark - layout
- (void)setupAssetView {
    [self.view addSubview:self.assetsHeadView];
    [self.view addSubview:self.threeBtn];
//    [self.view addSubview:self.nodataView];
    
    
    [self.assetsHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.equalTo(self.headView.mas_bottom).mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth, FIT(170)));
    }];
    
    [self.threeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(FIT(0));
        make.top.equalTo(self.assetsHeadView.mas_bottom).mas_equalTo(FIT(-36));
        make.size.mas_equalTo(CGSizeMake(ScreenWidth, FIT(72)));
    }];
    CGFloat tableView_H = ScreenHeight-NavigationStatusBarHeight-FIT(36);
    [self.view addSubview:self.assetTableView];
    [self.assetTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.threeBtn.mas_bottom).mas_equalTo(0);
        make.left.mas_equalTo(FIT(13));
        make.size.mas_equalTo(CGSizeMake(ScreenWidth-FIT(36), tableView_H));
    }];
    
//    [self.nodataView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(0);
//        make.left.mas_equalTo(FIT(18));
//        make.size.mas_equalTo(CGSizeMake(ScreenWidth-FIT(36), ScreenHeight));
//    }];
    
}

#pragma mark - UI
- (YQAssetsHeadView *)assetsHeadView {
    if (!_assetsHeadView) {
        _assetsHeadView = [[YQAssetsHeadView alloc] init];
    }
    return _assetsHeadView;
}

- (YQThreeBtnView *)threeBtn {
    if (!_threeBtn) {
        _threeBtn = [[YQThreeBtnView alloc] init];
        @weakify(self);
        _threeBtn.block = ^(NSInteger tag) {
            //100扫一扫 101收款 102转账
            @strongify(self);
            NSDictionary *vcDict = @{@"100":[YQSanningCodeVC new],
                                     @"101":[YQCollectionVC new],
                                     @"102":[YQTransferVC new]
                                     };
            YQ_PUSH([vcDict objectForKey:StringFromLongInt(tag)]);
        };
    }
    return _threeBtn;
}


- (UITableView *)assetTableView {
    if (!_assetTableView) {
        _assetTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _assetTableView.backgroundColor = [UIColor clearColor];
        _assetTableView.delegate = self;
        _assetTableView.dataSource = self;
//        YQ_TableView_Empty(_assetTableView);
        [_assetTableView  setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        
        [_assetTableView registerClass:[YQAssetsCell class] forCellReuseIdentifier:YQ_AssetsCell];
    }
    return _assetTableView;
}

- (YQNoDataView *)nodataView {
    if (!_nodataView) {
        _nodataView = [[YQNoDataView alloc] init];
        _nodataView.describeLab.text = @"您还没有创建地址，";
        [_nodataView showNoDataView];
        @weakify(self);
        _nodataView.PushBlock = ^{
            @strongify(self);
            YQ_PUSH([YQNewWalletAddressVC new]);
        };
    }
    return _nodataView;
}

//- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
//    return [UIImage imageNamed:@"scanning"];
//}
//
//- (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state {
//    NSString *text = @"Learn more";
//    UIFont   *font = [UIFont systemFontOfSize:15.0];
//    // 设置默认状态、点击高亮状态下的按钮字体颜色
//    UIColor  *textColor = MainBlueColor;
//
//    NSMutableDictionary *attributes = [NSMutableDictionary new];
//    [attributes setObject:font      forKey:NSFontAttributeName];
//    [attributes setObject:textColor forKey:NSForegroundColorAttributeName];
//
//    return [[NSAttributedString alloc] initWithString:text attributes:attributes];
//}

#pragma mark - delegate/datasources
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return FIT(52);
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    }else {
        return FIT(36);
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0001;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YQAssetsCell *cell = [tableView dequeueReusableCellWithIdentifier:YQ_AssetsCell forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    YQ_PUSH([YQNewWalletAddressVC new]);
}

@end
